package main

import (
	"fmt"
	"time"
)

func main() {
	//ParseDuration 解析持续时间字符串。 持续时间字符串是一个可能有符号的十进制数序列，每个都有可选的分数和单位后缀，例如“300ms”、“-1.5h”或“2h45m”。
	//有效时间单位为“ns”、“us”（或“µs”）、“ms”、“s”、“m”、“h”。

	hours, _ := time.ParseDuration("10h")
	complex, _ := time.ParseDuration("1h10m10s")
	micro, _ := time.ParseDuration("1µs")
	// The package also accepts the incorrect but common prefix u for micro.
	micro2, _ := time.ParseDuration("1us")

	fmt.Println(hours)
	fmt.Println(complex)
	fmt.Printf("There are %.0f seconds in %v.\n", complex.Seconds(), complex)
	fmt.Printf("There are %d nanoseconds in %v.\n", micro.Nanoseconds(), micro)
	fmt.Printf("There are %6.2e seconds in %v.\n", micro2.Seconds(), micro)
	//10h0m0s
	//1h10m10s
	//There are 4210 seconds in 1h10m10s.
	//There are 1000 nanoseconds in 1µs.
	//There are 1.00e-06 seconds in 1µs.
}
